import gosu.SampleInstance;

import org.jruby.*;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.anno.JRubyMethod;
import static org.jruby.RubyNumeric.*;


public class SampleInstanceProxy extends RubyObject {
  private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
      return new SampleInstanceProxy(runtime, klass);
    }
  };

  private SampleInstance _sampleInstance;

  private final Ruby _runtime;

  public static void createSampleInstanceClass(Ruby runtime) {
    RubyModule mGosu = runtime.getModule("Gosu");
    RubyClass cSampleInstance = mGosu.defineClassUnder("SampleInstance", runtime.getObject(), ALLOCATOR);

    cSampleInstance.defineAnnotatedMethods(SampleInstanceProxy.class);
  }


  public SampleInstanceProxy(Ruby runtime, RubyClass type) {
    super(runtime, type);
    _runtime = runtime;
  }


  public SampleInstance getSampleInstance() { return _sampleInstance; }


  public void setSampleInstance(SampleInstance si) { _sampleInstance = si; }


  @JRubyMethod(name = "playing?")
  public IRubyObject isPlaying() {
    return _runtime.newBoolean(_sampleInstance.isPlaying());
  }


  @JRubyMethod(name = "stop")
  public IRubyObject stop() {
    _sampleInstance.stop();
    return _runtime.getNil();
  }
               

  @JRubyMethod(name = "volume=",
               required = 1)
  public IRubyObject setVolume(IRubyObject vol) {
    _sampleInstance.setVolume((float) num2dbl(vol));
    return vol;
  }


  @JRubyMethod(name = "pan=",
               required = 1)
  public IRubyObject setPan(IRubyObject pan) {
    _sampleInstance.setPan((float) num2dbl(pan));
    return pan;
  }


  @JRubyMethod(name = "speed=",
               required = 1)
  public IRubyObject setSpeed(IRubyObject speed) {
    _sampleInstance.setSpeed((float) num2dbl(speed));
    return speed;
  }
}
